﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace CVSS.Client.BDM.UI
{
    partial class EscortManageFormMDT
    {
        /// <summary>
        /// 窗体界面
        /// </summary>
        private EscortManageForm form = null;
        /// <summary>
        /// 构造函数
        /// </summary>
        public EscortManageFormMDT()
        {
            try
            {
                form = new EscortManageForm();
                form.Load += new EventHandler(form_Load);
                form.btn_Add.Click += new EventHandler(btn_Add_Click);
                form.btn_Delete.Click += new EventHandler(btn_Delete_Click);
                form.btn_Modify.Click += new EventHandler(btn_Modify_Click);
                form.btn_Query.Click += new EventHandler(btn_Query_Click);
                form.btn_Save.Click += new EventHandler(btn_Save_Click);
                form.dvp_DataView.OnDataChangedHandlerEvent += new SysCommon.UI.DataGridViewForPageCtrl.OnDataChangedHandler(dvp_DataView_OnDataChangedHandlerEvent);
                
                form.dvp_DataView.dg_DataView.SelectionChanged += new EventHandler(dg_DataView_SelectionChanged);
              
                 
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error(
                    "调用DangerCargoManageFormMDT.DangerCargoManageFormMDT()出错", ex);
            }
        }
        void btn_Save_Click(object sender, EventArgs e)
        {
            Save();
            SetDataValueUnEditable();
        }

        void btn_Query_Click(object sender, EventArgs e)
        {
            BeginQuery();
        }

        void btn_Modify_Click(object sender, EventArgs e)
        {
            SetDataValueEditable();
            Modify();
        }

        void btn_Delete_Click(object sender, EventArgs e)
        {
            Delete();
        }

        void btn_Add_Click(object sender, EventArgs e)
        {
            SetDataValueEditable();
            Add();
        }
        //设置文本框，按钮属性
        private void SetDataValueUnEditable()
        {
            form.txt_Name.ReadOnly = true;
            form.txt_IDCARD.ReadOnly = true;
            form.txt_EscortID.ReadOnly = true;
            form.txt_TEL.ReadOnly = true;
            SetAllButtonAvailable();

        }
        private void SetDataValueEditable()
        {

            form.txt_Name.ReadOnly = false; ;
            form.txt_IDCARD.ReadOnly = false;
            form.txt_EscortID.ReadOnly = false;
            form.txt_TEL.ReadOnly = false;
          
        }
        private void SetAllButtonAvailable()
        {
            form.btn_Add.Enabled = true;
            form.btn_Delete.Enabled = true;
            form.btn_Modify.Enabled = true;
            form.btn_Query.Enabled = true;
         


        }

        private void BindingData(object ob)
        {

            try
            {
                //form.txt_EscortID.Clear();
                //form.txt_IDCARD.Clear();
               
                //form.txt_Name.Clear();
                //form.txt_TEL.Clear();
                form.txt_EscortID.DataBindings.Clear();
                form.txt_IDCARD.DataBindings.Clear();
                form.txt_Name.DataBindings.Clear();
                form.txt_TEL.DataBindings.Clear();
                form.cmb_CompanyName.DataBindings.Clear();
                form.cmb_Sex.DataBindings.Clear();
                form.dtp_Birthday.DataBindings.Clear();
                form.txt_EscortID.DataBindings.Add(new Binding("Text", ob, "ESCORTCARD", true));
                form.txt_IDCARD.DataBindings.Add(new Binding("Text", ob, "IDCARD", true));
                form.txt_Name.DataBindings.Add(new Binding("Text", ob, "NAME", true));
                form.txt_TEL.DataBindings.Add(new Binding("Text", ob, "TEL", true));
                form.cmb_CompanyName.DataBindings.Add(new Binding("Text",ob,"DANGERCOMPANYNAME",true));
                form.cmb_Sex.DataBindings.Add(new Binding("Text",ob,"SEXNAME",true));
                form.dtp_Birthday.DataBindings.Add(new Binding("Text",ob,"BIRTHDAY",true));

            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用BindingData出错", ex);
            }
        }

        #region UnBindingData()
        /// <summary>
        /// 撤消DataGridView跟txt的数据绑定
        /// </summary>
        private void UnBindingData()
        {
            try
            {
                form.txt_EscortID.DataBindings.Clear();
                form.txt_IDCARD.DataBindings.Clear();
                form.txt_Name.DataBindings.Clear();
                form.txt_TEL.DataBindings.Clear();
                form.cmb_CompanyName.DataBindings.Clear();
                form.cmb_Sex.DataBindings.Clear();
                form.dtp_Birthday.DataBindings.Clear();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用UnBindingData()出错", ex);
            }
        }
        #endregion

        /// <summary>
        /// 显示窗体
        /// </summary>
        public bool ShowForm()
        {
            try
            {
                form.ShowDialog();
                return true;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error(
                    "调用DangerCargoManageFormMDT.ShowForm()出错", ex);
            }
            return false;
        }
        /// <summary>
        /// 加载窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void form_Load(object sender, EventArgs e)
        {
            try
            {
                InitDataGridView();

                QueryBaseInfo();
                BeginQuery();
               
                //SysCommon.Entity.Business.DCS.View.View_Escort_Ety[] etys = (SysCommon.Entity.Business.DCS.View.View_Escort_Ety[])form.dvp_DataView.dg_DataView.DataSource;
                //BindingData(etys);
                
                SetDataValueUnEditable();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error(
                    "调用DangerCargoManageFormMDT.form_Load(object sender, EventArgs e)出错", ex);
            }
        }
    }
}
